package com.orange.base.component.biztool.simulateddata.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.orange.base.component.biztool.simulateddata.service.impl.AddressStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.Area3Strategy;
import com.orange.base.component.biztool.simulateddata.service.impl.Area5Strategy;
import com.orange.base.component.biztool.simulateddata.service.impl.BullShitStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.ChineseNameStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.CiStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.CustomArrayStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.CustomSqlStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.DateStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.DateTimeStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.DictStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.EmailStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.FileStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.IdCard;
import com.orange.base.component.biztool.simulateddata.service.impl.IdiomStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.MobileStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.NumberStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.PinyinStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.PrimaryTableColumnValueStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.SerialNumberStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.TableColumnValueStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.TextStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.UUIDStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.Word2Strategy;
import com.orange.base.component.biztool.simulateddata.service.impl.WordStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.XiehouyuStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.YearMonthStrategy;
import com.orange.base.component.biztool.simulateddata.service.impl.YearStrategy;

/**
 * 模拟数据工具
 *
 * @author biankudingcha
 * @date: 2022-08-15
 * @since 0.5.0
 */
public class SimulatedDataContext {

    private static final Map<String, SimulatedDataStrategy> SIMULATEDDATA_STRATEGY_MAP = new HashMap<String, SimulatedDataStrategy>();

    static {
        {
            YearStrategy yearStrategy = new YearStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(yearStrategy.getType(), yearStrategy);
        }
        {
            YearMonthStrategy yearMonthStrategy = new YearMonthStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(yearMonthStrategy.getType(), yearMonthStrategy);
        }
        {
            XiehouyuStrategy xiehouyuStrategy = new XiehouyuStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(xiehouyuStrategy.getType(), xiehouyuStrategy);
        }
        {
            WordStrategy wordStrategy = new WordStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(wordStrategy.getType(), wordStrategy);
        }
        {
            Word2Strategy word2Strategy = new Word2Strategy();
            SIMULATEDDATA_STRATEGY_MAP.put(word2Strategy.getType(), word2Strategy);
        }
        {
            UUIDStrategy uuidStrategy = new UUIDStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(uuidStrategy.getType(), uuidStrategy);
        }
        {
            TextStrategy textStrategy = new TextStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(textStrategy.getType(), textStrategy);
        }
        {
            TableColumnValueStrategy tableColumnValueStrategy = new TableColumnValueStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(tableColumnValueStrategy.getType(), tableColumnValueStrategy);
        }
        {
            SerialNumberStrategy serialNumberStrategy = new SerialNumberStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(serialNumberStrategy.getType(), serialNumberStrategy);
        }
        {
            PrimaryTableColumnValueStrategy primaryTableColumnValueStrategy = new PrimaryTableColumnValueStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(primaryTableColumnValueStrategy.getType(), primaryTableColumnValueStrategy);
        }
        {
            PinyinStrategy pinyinStrategy = new PinyinStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(pinyinStrategy.getType(), pinyinStrategy);
        }
        {
            NumberStrategy numberStrategy = new NumberStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(numberStrategy.getType(), numberStrategy);
        }
        {
            MobileStrategy mobileStrategy = new MobileStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(mobileStrategy.getType(), mobileStrategy);
        }
        {
            IdiomStrategy idiomStrategy = new IdiomStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(idiomStrategy.getType(), idiomStrategy);
        }
        {
            IdCard idCard = new IdCard();
            SIMULATEDDATA_STRATEGY_MAP.put(idCard.getType(), idCard);
        }
        {
            FileStrategy fileStrategy = new FileStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(fileStrategy.getType(), fileStrategy);
        }
        {
            EmailStrategy emailStrategy = new EmailStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(emailStrategy.getType(), emailStrategy);
        }
        {
            EmailStrategy emailStrategy = new EmailStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(emailStrategy.getType(), emailStrategy);
        }
        {
            DictStrategy dictStrategy = new DictStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(dictStrategy.getType(), dictStrategy);
        }
        {
            DateTimeStrategy dateTimeStrategy = new DateTimeStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(dateTimeStrategy.getType(), dateTimeStrategy);
        }
        {
            DateTimeStrategy dateTimeStrategy = new DateTimeStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(dateTimeStrategy.getType(), dateTimeStrategy);
        }
        {
            DateStrategy dateStrategy = new DateStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(dateStrategy.getType(), dateStrategy);
        }
        {
            CustomSqlStrategy customSqlStrategy = new CustomSqlStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(customSqlStrategy.getType(), customSqlStrategy);
        }
        {
            CustomArrayStrategy customArrayStrategy = new CustomArrayStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(customArrayStrategy.getType(), customArrayStrategy);
        }
        {
            CiStrategy ciStrategy = new CiStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(ciStrategy.getType(), ciStrategy);
        }
        {
            ChineseNameStrategy chineseNameStrategy = new ChineseNameStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(chineseNameStrategy.getType(), chineseNameStrategy);
        }
        {
            BullShitStrategy bullShitStrategy = new BullShitStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(bullShitStrategy.getType(), bullShitStrategy);
        }
        {
            Area5Strategy area5Strategy = new Area5Strategy();
            SIMULATEDDATA_STRATEGY_MAP.put(area5Strategy.getType(), area5Strategy);
        }
        {
            Area3Strategy area3Strategy = new Area3Strategy();
            SIMULATEDDATA_STRATEGY_MAP.put(area3Strategy.getType(), area3Strategy);
        }
        {
            AddressStrategy addressStrategy = new AddressStrategy();
            SIMULATEDDATA_STRATEGY_MAP.put(addressStrategy.getType(), addressStrategy);
        }
    }

    public static Object getValue(String type, SimulatedDataParam param) {
        if (SIMULATEDDATA_STRATEGY_MAP.containsKey(type)) {
            return SIMULATEDDATA_STRATEGY_MAP.get(type).getValue(param);
        }
        return null;
    }

    public static Map<String, SimulatedDataStrategy> getSimulatedDataStrategys() {
        return SIMULATEDDATA_STRATEGY_MAP;
    }

    public static void setSimulatedDataDao(SimulatedDataDao simulatedDataDao) {
        for (Iterator<Entry<String, SimulatedDataStrategy>> iter = SIMULATEDDATA_STRATEGY_MAP.entrySet()
            .iterator(); iter.hasNext();) {
            Entry<String, SimulatedDataStrategy> entry = iter.next();
            SimulatedDataStrategy simulatedDataStrategy = entry.getValue();
            simulatedDataStrategy.setSimulatedDataDao(simulatedDataDao);
        }
    }

    public static void setSimulatedDataDictService(SimulatedDataDictService simulatedDataDictService) {
        for (Iterator<Entry<String, SimulatedDataStrategy>> iter = SIMULATEDDATA_STRATEGY_MAP.entrySet()
            .iterator(); iter.hasNext();) {
            Entry<String, SimulatedDataStrategy> entry = iter.next();
            SimulatedDataStrategy simulatedDataStrategy = entry.getValue();
            simulatedDataStrategy.setSimulatedDataDictService(simulatedDataDictService);
        }
    }

    public static List<DictInfo> getTypeDict() {
        List<DictInfo> dictInfoList = new ArrayList<DictInfo>();
        for (Iterator<Entry<String, SimulatedDataStrategy>> iter = SIMULATEDDATA_STRATEGY_MAP.entrySet()
            .iterator(); iter.hasNext();) {
            Entry<String, SimulatedDataStrategy> entry = iter.next();
            SimulatedDataStrategy simulatedDataStrategy = entry.getValue();
            DictInfo dictInfo = new DictInfo();
            dictInfo.setCode(simulatedDataStrategy.getType());
            dictInfo.setName(simulatedDataStrategy.getCaption());
            dictInfoList.add(dictInfo);
        }
        return dictInfoList;
    }

}
